//管理首页相关数据的vuex子模块
import { 
    reqCategoryList,
    reqBannerList,
    // reqFloors,
    // reqBanners
  } from '@/api'

const state= {
    crategoryList:[],
    bannerList:[]
}
const mutations={
    RECEIVE_CATEGORY_LIST(state,crategoryList){
        state.crategoryList = crategoryList
    }, //这个state是局部的state
    RECEIVE_BANNER_LIST(state,bannerList){
        state.bannerList = bannerList
    }
} 

const actions={
    //commit触发的是所有的匹配的actions匹配上了就可以调用
    // 获取三级分类的异步action
    async getCrategroyList({commit}){
        const result = await reqCategoryList()
        if(result.code === 0){
            const crategoryList = result.data.splice(0,16)
            commit('RECEIVE_CATEGORY_LIST',crategoryList)
        }
    },
    async getBannerList({commit}){
        const result = await reqBannerList();
        if(result.code === 0){
            const bannerList = result.data
            commit('RECEIVE_BANNER_LIST',bannerList)
        } 
    }
   
}
const getters={
    yyy(state){}
}

export default {
    state,
    mutations,
    actions,
    getters
}